<template>
    <div>
        <div>
            <el-table
                    :data="tableData"
                    stripe
                    style="width: 100%">
                <el-table-column
                        prop="uname"
                        label="考试人员">
                </el-table-column>
                <el-table-column
                        prop="score"
                        label="考试分数">
                </el-table-column>
                <el-table-column label="操作">
                    <template scope="scope">
                        <el-button @click="handleClick(scope.$index)" type="text" size="small">录入分数</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <el-dialog title="录入分数" :visible.sync="dialogFormVisible">
            <el-form>
                <el-form-item label="分数" :label-width="formLabelWidth">
                    <el-input v-model="score" auto-complete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import moment from 'moment';
    import ElFormItem from "../../../../node_modules/element-ui/packages/form/src/form-item";
    import ElInput from "../../../../node_modules/element-ui/packages/input/src/input";
    import ElInputNumber from "../../../../node_modules/element-ui/packages/input-number/src/input-number";
    export default {
        components: {ElInputNumber, ElInput, ElFormItem}, data() {
            return {
                tableData: [],
                score:0,
                dialogFormVisible:false,
                formLabelWidth: '120px',
                sid:''
            }
        },
        activated(){
            this.getScore();
        },
        methods: {
            getScore(){
                let self = this;
                this.tableData = [];
                let eid = this.$route.query.item.id;
                this.$axioxs.get("/score/get?eid=" + eid)
                    .then(function (res) {
                        self.tableData = res.data.records;
//                        res.data.records.forEach(item => {
//                            console.log(item);
//                            item.name = item.students.name;
//                            self.tableData.push(item);
//                        })
                    })
            },
            handleClick(index) {
                this.dialogFormVisible = true;
                this.sid = this.tableData[index].id;
            },
            submitForm(){
                let self = this;
                this.$axioxs.post("/score/save?sid="+this.sid+"&score="+this.score)
                    .then(function (res) {
                        self.dialogFormVisible = false;
                        self.score = 0;
                        self.sid = '';
                        self.getScore();
                    })
            }
        }
    }
</script>